home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0064_Unit to handle bit operations.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  915b  |  36 lines

  1. { Ok Here is a nice little unit to handle bit operations. }
  2. UNIT Bits;
  3.  
  4. INTERFACE
  5.  
  6. function CheckBit(bit_number : byte; byte_on : byte) : boolean;
  7. function ChangeBit(bit_number : byte; byte_on : byte) : byte;
  8. function BitON(bit_number : byte; byte_on : byte) : byte;
  9. function BitOFF(bit_number : byte; byte_on : byte) : byte;
  10.  
  11. IMPLEMENTATION
  12.  
  13. const
  14.   test : array[0..7] of byte = (1,2,4,8,$10,$20,$40,$80);
  15.  
  16. function CheckBit(bit_number : byte; byte_on : byte) : boolean;
  17. begin
  18.   CheckBit := byte_on and test[bit_number] <> 0
  19. end;
  20.  
  21. function ChangeBit(bit_number : byte; byte_on : byte) : byte;
  22. begin
  23.   ChangeBit := byte_on xor test[bit_number]
  24. end;
  25.  
  26. function BitON(bit_number : byte; byte_on : byte) : byte;
  27. begin
  28.   BitON := byte_on or test[bit_number]
  29. end;
  30.  
  31. function BitOFF(bit_number : byte; byte_on : byte) : byte;
  32. begin
  33.   BitOFF := byte_on and not test[bit_number]
  34. end;
  35.  
  36. end.